#include <cstdio>
#include <cstring>

#define MAX_SIZE 10000

int n;

int count(int top, int down) {
	if (top == down) return 1;
	int total = 1;
	for (int i = 0; i < top; ++i) {
		total *= (down-i);
	}
	for (int i = 1; i <= top; ++i) {
		total /= i;
	}
	return total;
}

int pre_post(char pre[], char post[], int pre_start, int pre_end, int post_start, int post_end) {
	if (pre_start > pre_end || post_start > post_end) return 1;

	int i = pre_start, j = post_start;
	int c = 0;
	int data = 1;
	char root = pre[pre_start];
	while (i <= pre_end) {
		if (root == post[j]) {
			data *= pre_post(pre, post, i+1, j-post_start+pre_start+1, post_start, j-1);
			++c;
			i = j-post_start+pre_start+1;
			root = pre[i];
		}
		++j;
	}
	return data * count(c, n);
}

int main() {
	char pre[MAX_SIZE], post[MAX_SIZE];
	while (scanf("%d %s %s", &n, pre, post) == 3) {
		printf("%d\n", pre_post(pre, post, 1, strlen(pre)-1, 0, strlen(post)-2));
	}
}